package club.zhilin.guli.service.edu.controller.backend;


import club.zhilin.guli.common.base.result.CommonResult;
import club.zhilin.guli.service.edu.domain.Video;
import club.zhilin.guli.service.edu.service.IVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author zhilin
 * @since 2022-01-11 15:29:01
 */
@Api(tags = "课时管理")
@RestController
@RequestMapping("/admin/edu/video")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class VideoController {

    private final IVideoService iVideoService;

    @ApiOperation("新增课时")
    @PostMapping("/video")
    public CommonResult<String> save(@RequestBody Video video) {
        boolean result = iVideoService.save(video);
        return result ? CommonResult.success("保存成功") : CommonResult.failed("保存失败");
    }

    @ApiOperation("通过课时id删除课时")
    @DeleteMapping("/video/{id}")
    public CommonResult<String> remove(@PathVariable String id) {
        iVideoService.removeMediaVideo(id);
        boolean result = iVideoService.removeById(id);
        return result ? CommonResult.success("删除成功") : CommonResult.failed("删除失败");
    }

    @ApiOperation("通过课时对象修改课时")
    @PutMapping("/video")
    public CommonResult<String> update(@RequestBody Video video) {
        boolean result = iVideoService.updateById(video);
        return result ? CommonResult.success("更新成功") : CommonResult.failed("更新失败");
    }

    @ApiOperation("通过课时id查询课时对象")
    @GetMapping("/video/{id}")
    public CommonResult<Video> selectOne(@PathVariable String id) {
        Video video = iVideoService.getById(id);
        return video != null ? CommonResult.success(video) : CommonResult.failed("数据不存在");
    }
}

